package com.small.xx.ai.spring.toolcall.component.weather.function;

import com.fasterxml.jackson.annotation.JsonClassDescription;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import com.small.xx.ai.spring.toolcall.component.weather.Response;
import com.small.xx.ai.spring.toolcall.component.weather.method.WeatherTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

import java.util.function.Function;

public class WeatherFunctionService implements Function<WeatherFunctionService.Request, Response> {

    private static final Logger logger = LoggerFactory.getLogger(WeatherFunctionService.class);

    public WeatherFunctionService() {
    }

    @Override
    public Response apply(Request request) {
        if (request == null || !StringUtils.hasText(request.city())) {
            logger.error("Invalid request: city is required.");
            return null;
        }
        System.out.println("WeatherFunctionService.apply");
        return new WeatherTools().getWeatherServiceMethod(request.city(), 2);
    }

    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonClassDescription("Weather Service API request")
    public record Request(
        @JsonProperty(required = true, value = "city") @JsonPropertyDescription("城市名称") String city,

        @JsonProperty(required = true, value = "days") @JsonPropertyDescription("天气预报的天数。值范围为1到2") int days) {
    }
}